package com.ruoyi.web.controller.repository;

import java.util.List;

import com.ruoyi.system.repository.domain.MiniOrder;
import com.ruoyi.system.repository.domain.Order;
import com.ruoyi.system.repository.domain.Ordertable;
import com.ruoyi.system.repository.service.IOrdertableService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单Controller
 *
 * @author qiang
 * @date 2021-01-01
 */
@RestController
@RequestMapping("/repository/ordertable")
public class    OrdertableController extends BaseController {
    @Autowired
    private IOrdertableService ordertableService;

/**
 * 查询订单列表
 */
@PreAuthorize("@ss.hasPermi('repository:ordertable:list')")
@GetMapping("/list")
        public TableDataInfo list(Ordertable ordertable) {
        startPage();
        List<Ordertable> list = ordertableService.selectOrdertableList(ordertable);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('repository:ordertable:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Ordertable ordertable) {
        List<Ordertable> list = ordertableService.selectOrdertableList(ordertable);
        ExcelUtil<Ordertable> util = new ExcelUtil<Ordertable>(Ordertable. class);
        return util.exportExcel(list, "ordertable");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('repository:ordertable:query')")
    @GetMapping(value = "/{orderid}")
    public AjaxResult getInfo(@PathVariable("orderid") String orderid) {
        return AjaxResult.success(ordertableService.selectOrdertableById(orderid));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('repository:ordertable:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ordertable ordertable) {
        return toAjax(ordertableService.insertOrdertable(ordertable));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('repository:ordertable:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ordertable ordertable) {
        return toAjax(ordertableService.updateOrdertable(ordertable));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('repository:ordertable:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderid}")
    public AjaxResult remove(@PathVariable String[] orderid) {
        return toAjax(ordertableService.deleteOrdertableByIds(orderid));
    }


    //查询用户所有订单详细信息
    @GetMapping("public/findAllOrderByName")
    public List<Order> findAllOrderByName(String userName)
    {
        return ordertableService.findAllOrderByName(userName);
    }

    //查询用户今日订单缩略信息
    @GetMapping("public/findTodayMiniOrder")
    public List<MiniOrder> findTodayMiniOrder(String userName)
    {
        return ordertableService.findTodayMiniOrder(userName);
    }
    //查询用户所有订单缩略信息
    @GetMapping("public/findAllMiniOrder")
    public List<MiniOrder> findAllMiniOrder(String userName)
    {
        return ordertableService.findAllMiniOrder(userName);
    }

    //查询一个订单的详细信息
    @GetMapping("public/findOneOrder")
    public Order findOneOrder(String userName,int orderId)
    {
        return ordertableService.findOneOrder(userName,orderId);
    }

    //增加一个订单条目
    @GetMapping("public/addOneOrder")
    public boolean addOneOrder(Order order)
    {
        return ordertableService.addOneOrder(order);
    }

    //增加一个订单条目
    @GetMapping("public/addOneOrderByStr")
    public boolean addOneOrderByStr(String userName,String drinkStr) {
        return ordertableService.addOneOrderByStr(userName,drinkStr);
    }
}
